package com.area42games.grammar;

import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTreeAdaptor;

import com.area42games.grammar.trees.DiceTree;
import com.area42games.grammar.trees.DiceTreeDice;
import com.area42games.grammar.trees.EvalContext;

public class DiceTreeAdaptor extends CommonTreeAdaptor 
{
	private EvalContext context;

	public DiceTreeAdaptor(EvalContext context) 
	{
		this.context = context;
	}

	public Object create(Token payload)
	{
		if(payload != null)
		{
			if(payload.getType() == DiceLexer.D || payload.getType() == DiceLexer.CD)
			{
				return new DiceTreeDice(payload,this.context);
			}
		}
		return new DiceTree(payload,this.context);
	}
}
